/*
 * @Author: c
 * @Date: 2023-12-04 21:49:59
 * @LastEditTime: 2023-12-16 20:41:17
 * @LastEditors: c
 * @Description:
 * @FilePath: \vue3-element-admin\src\api\auth\index.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { CaptchaResult, LoginData, LoginResult } from "./types";
import { Post } from "@/http/http";
import { ApiUrl } from "../api.url";

/**
 * 登录API
 *
 * @param data {LoginData}
 * @returns
 */
export function loginApi(data: LoginData): Promise<LoginResult> {
  const formData = new FormData();
  formData.append("username", data.username);
  formData.append("password", data.password);

  return Post<LoginData, LoginResult>(ApiUrl.Auth.V1, data);
}

/**
 * 注销API
 */
export function logoutApi() {
  return request({
    url: "/api/v1/auth/logout",
    method: "delete",
  });
}

/**
 * 获取验证码
 */
export function getCaptchaApi(): AxiosPromise<CaptchaResult> {
  return request({
    url: "/api/v1/auth/captcha",
    method: "get",
  });
}
